Skip to content

Deploy: CDN cache headers for HTML and an nginx smoke test in CI - #2

Merged
Nik-code merged 1 commit into
mainfrom
deploy/edge-cache-and-nginx-smoke
Nov 3, 2026
Merged

Nik-code merged 1 commit into
mainfrom
deploy/edge-cache-and-nginx-smoke

Conversation

@Nik-code

@Nik-code Nik-code commented Nov 3, 2026

Copy link
Copy Markdown
Owner

This is a follow-up to #1. It covers the origin-load side of the 27 Oct indexing drop.

Why

On 26–27 Oct the origin slowed down (p95 1.97 s, max 30 s) and dropped two uptime checks, right while Googlebot was recrawling the site that had just tripled in size. Cloudflare answers cf-cache-status: DYNAMIC, so every crawler fetch went all the way to the origin. On top of that, the 25 Oct deploy briefly served a self-redirect on every aircraft page, and nothing in CI would have caught it.

Changes

  • Cache headers. nginx now sends Cache-Control: public, max-age=0, s-maxage=3600, stale-while-revalidate=86400 on HTML, and s-maxage=3600 on the sitemap, robots.txt and RSC .txt files. Browsers still revalidate every time. /_next/static and /data keep their own headers.
  • open_file_cache for the ~10k files in the export.
  • scripts/nginx-smoke.mjs (npm run nginx:smoke), run in CI against nginx:1.27-alpine with the production config. It checks that:
    • all sitemap URLs return 200 with no redirect;
    • lowercase and hyphen-less spellings of about 300 registrations return 301 to the canonical page;
    • an unknown registration returns 404;
    • the cache headers are present.

Verified locally

The test ran on nginx 1.24 against the export built from main:

  • New config: all 5,248 requests pass.
  • 20dd041 config: the test fails with /aircraft/VT-AAT: 301, want 200 (Location …/aircraft/VT-AAT), which is the 25 Oct loop, so the test would have caught it.

Still needed in Cloudflare (Nik)

The headers do nothing until Cloudflare is allowed to cache HTML:

  • Caching → Cache Rules → hostname vtaircrafts.in, Eligible for cache, Edge TTL Use cache-control header if present, Browser TTL Respect origin.
  • After each deploy, purge the cache (Caching → Configuration → Purge Everything), or let the 1 h s-maxage expire.
  • Security → Bots: make sure verified bots (Googlebot) are allowed and never challenged.

Generated by Claude Code

- nginx sends Cache-Control with s-maxage=3600 on HTML, sitemap and robots, so Cloudflare
  can serve crawlers from the edge once a Cache Rule makes HTML eligible. Browsers still
  revalidate every time. open_file_cache for the 10k files in the export.
- scripts/nginx-smoke.mjs runs in CI against nginx:1.27-alpine with the production config:
  every sitemap URL answers 200 (no redirect), lowercase and hyphen-less registrations 301
  to the canonical page, unknown registrations 404, and cache headers are present. Against
  the 20dd041 config it fails on every aircraft page with the self-redirect.
@Nik-code
Nik-code merged commit 6dd9445 into main Nov 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants